import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    component: () => import('@/views/index/index.vue'),
  },
  {
    path: '/product/index',
    component: () => import('@/views/product/index.vue'),
  },
  {
    path: '/product/detail',
    component: () => import('@/views/product/detail.vue'),
  },
  {
    path: '/order/index',
    component: () => import('@/views/order/index.vue'),
  },
  {
    path: '/order/trade',
    component: () => import('@/views/order/trade.vue'),
  },
  {
    path: '/address/index',
    component: () => import('@/views/address/index.vue'),
  },
  {
    path: '/address/detail',
    component: () => import('@/views/address/detail.vue'),
  },
]

const router = createRouter({
  routes,
  history: createWebHashHistory(),
  scrollBehavior(to, from, savedPosition) {
    if (to.hash) {
      return {
        el: to.hash,
      }
    } else if (savedPosition) {
      return savedPosition
    } else {
      return { top: 0 }
    }
  },
})

export default router
